//
//  UIBarButtonItem+Extension.swift
//  新浪微博练习02
//
//  Created by 曹魏 on 16/9/24.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
extension UIBarButtonItem {
    //添加一个构造方法
    convenience init(title: String = "",imageName: String? = nil,target: Any?, action: Selector) {
        let btn = UIButton()
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        //设置字体字号
        btn.titleLabel?.font = UIFont.systemFont(ofSize:14)
        if imageName != nil {
            
            btn.setImage(UIImage(named:imageName!), for: .normal)
            btn.setImage(UIImage(named:imageName! + "_highlighted"), for: .highlighted)
        }
        btn.sizeToFit()
        //添加按钮监听点击事件
        btn.addTarget(target, action: action, for: .touchUpInside)
        self.init()
        //给当前对象设置自定义视图
        self.customView = btn
        
        
    }
}
